package command

import (
	"com.mgface.disobj/metanode/mq/mgfacemq"
	"github.com/urfave/cli"
)

//todo 1.读取配置文件，覆盖默认值

//todo 2.根据配置文件来初始化文件存储还是缓存存储数据

//todo 3.判断如果是启用文件存储，启动的时候需要加载已有的文件数据

var startflag = []cli.Flag{
	cli.StringFlag{
		Name:     "na", //node address
		Usage:    "节点地址(node addres)",
		Required: true,
	},
	cli.StringFlag{
		Name:     "ca", //cluster address
		Usage:    "集群种子地址(cluster address).当节点只有自身时,把自己IP注册到gossip集群.",
		Required: true,
	},
	cli.StringFlag{
		Name:     "gna", //gossip node address
		Usage:    "集群节点goosip地址(gossip node address)",
		Required: true,
	},
	cli.StringFlag{
		Name:     "ms", //metadata store path
		Usage:    "元数据存储路径(metadata store path)",
		Required: true,
	},
	//todo 配置文件要单独处理
	cli.StringFlag{
		Name:     "file",
		Usage:    "配置文件",
		Required: false,
	},
}
var StartMNCommand = cli.Command{
	Name:    "start",
	Aliases: []string{"st"},
	Usage: `示例指令:
		startmetanode start -na 127.0.0.1:3001 -gna 127.0.0.1:10001 -ca 127.0.0.1:10001,127.0.0.1:10002 -ms C:\\metadata
		`,
	Flags: startflag,
	Action: func(ctx *cli.Context) error {
		//获得节点的地址
		na := ctx.String("na")
		//获得集群种子地址
		ca := ctx.String("ca")
		//获取集群节点goosip地址
		gna := ctx.String("gna")
		//获取元数据存储路径
		ms := ctx.String("ms")
		mgfacemq.Startengine(na, ca, gna, ms)
		return nil
	},
}
